package com.dhcy.mqtt.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dhcy.mqtt.model.DeviceClass;
import com.dhcy.mqtt.model.Equipment;
import com.dhcy.mqtt.model.MqttSetting;
import com.dhcy.mqtt.par.ht.*;
import com.dhcy.mqtt.result.ht.*;
import com.dhcy.mqtt.service.*;
import com.dhcy.mqtt.util.AppResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("ht")
@Api(value = "设备", tags = "ht")
public class HtController {

    @Autowired
    DeviceService deviceService;


    @Autowired
    OperationLogService operationLogService;

    @Autowired
    DeviceDataService deviceDataService;


    @Autowired
    SysResourceService sysResourceService;

    @Autowired
    RevEquipmentDataService revEquipmentDataService;

    @Autowired
    EquipmentService equipmentService;


    @GetMapping("deviceList.json")
    @ResponseBody
    @ApiOperation(value = "设备列表", notes = "设备列表", httpMethod = "GET", response = DeviceResult.class, produces = "application/json")
    TableResultData deviceList(DeviceListPar deviceListPar) {
        return deviceService.deviceList(deviceListPar);
    }


    @GetMapping("deviceListSimple.json")
    @ResponseBody
    @ApiOperation(value = "设备列表", notes = "设备列表", httpMethod = "GET", response = DeviceResult.class, produces = "application/json")
    AppResultData deviceListSimple(DeviceListPar deviceListPar) {
        return deviceService.deviceListSimple(deviceListPar);
    }

    @PostMapping("deviceAdd.json")
    @ResponseBody
    @ApiOperation(value = "添加修改设备", notes = "添加修改设备", httpMethod = "POST", produces = "application/json")
    AppResultData deviceAdd(DeviceAddPar deviceaddPar) {
        return deviceService.deviceAdd(deviceaddPar);
    }

    @PostMapping("deviceDel.json")
    @ResponseBody
    @ApiOperation(value = "删除设备", notes = "删除设备", httpMethod = "POST", produces = "application/json")
    AppResultData deviceDel(Integer id) {
        return deviceService.deviceDel(id);
    }


    @GetMapping("deviceClassList.json")
    @ResponseBody
    @ApiOperation(value = "设备列表", notes = "设备列表", httpMethod = "GET", response = DeviceResult.class, produces = "application/json")
    TableResultData deviceClassList(DeviceListPar deviceListPar) {
        return deviceService.deviceClassList(deviceListPar);
    }

    @PostMapping("deviceClassAdd.json")
    @ResponseBody
    @ApiOperation(value = "添加修改设备", notes = "添加修改设备", httpMethod = "POST", produces = "application/json")
    AppResultData deviceClassAdd(DeviceClass deviceaddPar) {
        return deviceService.deviceClassAdd(deviceaddPar);
    }

    @PostMapping("deviceClassDel.json")
    @ResponseBody
    @ApiOperation(value = "删除设备", notes = "删除设备", httpMethod = "POST", produces = "application/json")
    AppResultData deviceClassDel(Integer id) {
        return deviceService.deviceClassDel(id);
    }


    @GetMapping("settingList.json")
    @ResponseBody
    TableResultData settingList(DeviceListPar deviceListPar) {
        return deviceService.settingList(deviceListPar);
    }

    @PostMapping("settingAdd.json")
    @ResponseBody
    AppResultData settingAdd(MqttSetting mqttSetting) {
        return deviceService.settingAdd(mqttSetting);
    }

    @PostMapping("settingDel.json")
    @ResponseBody
    AppResultData settingDel(Integer id) {
        return deviceService.settingDel(id);
    }


    @GetMapping("operationLogList.json")
    @ResponseBody
    @ApiOperation(value = "操作日志列表", notes = "操作日志列表", httpMethod = "GET", response = OperationLogResult.class, produces = "application/json")
    TableResultData operationLogList(OperationLogListPar operationLogListPar) {
        return operationLogService.operationLogList(operationLogListPar);
    }

    @PostMapping("operationLogAdd.json")
    @ResponseBody
    @ApiOperation(value = "添加修改操作日志", notes = "添加修改操作日志", httpMethod = "POST", produces = "application/json")
    AppResultData operationLogAdd(OperationLogAddPar operationLogaddPar) {
        return operationLogService.operationLogAdd(operationLogaddPar);
    }

    @PostMapping("operationLogDel.json")
    @ResponseBody
    @ApiOperation(value = "删除操作日志", notes = "删除操作日志", httpMethod = "POST", produces = "application/json")
    AppResultData operationLogDel(Integer id) {
        return operationLogService.operationLogDel(id);
    }

    @GetMapping("deviceDataList.json")
    @ResponseBody
    @ApiOperation(value = "设备数据列表", notes = "设备数据列表", httpMethod = "GET", response = DeviceDataResult.class, produces = "application/json")
    TableResultData deviceDataList(DeviceDataListPar deviceDataListPar) {
        return deviceDataService.deviceDataList(deviceDataListPar);
    }

    @PostMapping("deviceDataAdd.json")
    @ResponseBody
    @ApiOperation(value = "添加修改设备数据", notes = "添加修改设备数据", httpMethod = "POST", produces = "application/json")
    AppResultData deviceDataAdd(DeviceDataAddPar deviceDataaddPar) {
        return deviceDataService.deviceDataAdd(deviceDataaddPar);
    }

    @PostMapping("deviceDataDel.json")
    @ResponseBody
    @ApiOperation(value = "删除设备数据", notes = "删除设备数据", httpMethod = "POST", produces = "application/json")
    AppResultData deviceDataDel(Integer id) {
        return deviceDataService.deviceDataDel(id);
    }

    @GetMapping("sysResourceList.json")
    @ResponseBody
    @ApiOperation(value = "菜单列表", notes = "菜单列表", httpMethod = "GET", response = SysResourceResult.class, produces = "application/json")
    TableResultData sysResourceList(SysResourceListPar sysResourceListPar) {
        return sysResourceService.sysResourceList(sysResourceListPar);
    }

    @PostMapping("sysResourceAdd.json")
    @ResponseBody
    @ApiOperation(value = "添加修改菜单", notes = "添加修改菜单", httpMethod = "POST", produces = "application/json")
    AppResultData sysResourceAdd(SysResourceAddPar sysResourceaddPar) {
        return sysResourceService.sysResourceAdd(sysResourceaddPar);
    }

    @PostMapping("sysResourceDel.json")
    @ResponseBody
    @ApiOperation(value = "删除菜单", notes = "删除菜单", httpMethod = "POST", produces = "application/json")
    AppResultData sysResourceDel(Integer id) {
        return sysResourceService.sysResourceDel(id);
    }

    @GetMapping("deviceCount.json")
    @ResponseBody
    @ApiOperation(value = "设备数量接口")
    AppResultData deviceCount() {
        return AppResultData.success("成功", deviceService.count());
    }

    @GetMapping("deviceDataCount.json")
    @ResponseBody
    @ApiOperation(value = "设备数据数量接口")
    AppResultData deviceDataCount() {
        return AppResultData.success("成功", deviceDataService.count());
    }

    @GetMapping("revEquipmentDataList.json")
    @ResponseBody
    @ApiOperation(value = "接收设备数据列表", notes = "接收设备数据列表", httpMethod = "GET", response = RevEquipmentDataResult.class, produces = "application/json")
    TableResultData revEquipmentDataList(RevEquipmentDataListPar revEquipmentDataListPar) {
        return revEquipmentDataService.revEquipmentDataList(revEquipmentDataListPar);
    }
    @GetMapping("lineChart.json")
    @ResponseBody
    @ApiOperation(value = "接收设备数据折线图", notes = "接收设备数据折线图", httpMethod = "GET", response = RevEquipmentDataResult.class, produces = "application/json")
    TableResultData lineChartDataList(RevEquipmentDataListPar revEquipmentDataListPar) {
        return revEquipmentDataService.lineChartDataList(revEquipmentDataListPar);
    }

    @GetMapping("equipmentList.json")
    @ResponseBody
    @ApiOperation(value = "设备列表", notes = "设备列表", httpMethod = "GET", response = EquipmentResult.class, produces = "application/json")
    TableResultData equipmentList(EquipmentListPar equipmentListPar) {
        return equipmentService.equipmentList(equipmentListPar);
    }
//
    @PostMapping("equipmentAdd.json")
    @ResponseBody
    @ApiOperation(value = "添加修改设备", notes = "添加修改设备", httpMethod = "POST", produces = "application/json")
    AppResultData equipmentAdd(EquipmentAddPar equipmentaddPar) {
        return equipmentService.equipmentAdd(equipmentaddPar);
    }
//
//    @PostMapping("asynEquipment.json")
//    @ResponseBody
//    @ApiOperation(value = "设备同步", notes = "设备同步", httpMethod = "POST", produces = "application/json")
//    AppResultData asynEquipment( @RequestBody List<Equipment> equipment) {
//        return equipmentService.asynEquipment(equipment);
//    }
//
//
    @PostMapping("equipmentDel.json")
    @ResponseBody
    @ApiOperation(value = "删除设备", notes = "删除设备", httpMethod = "POST", produces = "application/json")
    AppResultData equipmentDel(Integer id) {
        return equipmentService.equipmentDel(id);
    }
//
//    @GetMapping("equipmentCount.json")
//    @ResponseBody
//    @ApiOperation(value = "设备数量接口")
//    AppResultData equipmentCount() {
//        EquipmentListPar equipmentListPar = new EquipmentListPar();
//        return AppResultData.success("成功", equipmentService.count());
//    }
//
    @GetMapping("equipmentNumber.json")
    @ResponseBody
    @ApiOperation(value = "根据设备类型获取所有编号")
    AppResultData equipmentNumber() {
        EquipmentListPar equipmentListPar = new EquipmentListPar();
        return AppResultData.success("成功", equipmentService.getBaseMapper().selectList(new QueryWrapper<Equipment>().eq("is_del",0)));
    }

    @GetMapping("equipmentPush.json")
    @ResponseBody
    @ApiOperation(value = "根据设备类型获取所有编号")
    AppResultData equipmentPush(String code,String number,Integer num) {
        return AppResultData.success("成功", revEquipmentDataService.equipmentPush(code,number,num));
    }

}
